##coding:utf-8
from random import choice
import  os


#### define banner
def ban10():
    print(10*"#")

def ban20():
    print(20*"#")

def ban40():
    print(40*"#")


filename ='f:\\test.txt'
f=open(filename,"r")
lines=f.readlines()
x=''

count = len(open(filename,'rU').readlines())
if (int(count) % 2) !=0:
    print("为了适应比赛规则，请补齐为偶数参赛队！")
else:
    for line in lines:

        line=line.split(".")[-1]
        x+=line

        #L1.append(x)

    f.close()
    #print(L1)
    print("参赛分组情况如下：")
    ban20()
    print(x)
    ban20()

    L1=x.split()
    #print(L1)

    tmp_list=L1[:]
    L2=[]


    print()
    print()
    print("各队挑选对手过程如下：")
    ban40()

    savefile="f:\\result.txt"
    if os.path.exists(savefile):
        os.remove(savefile)
    for x in tmp_list:

        if len(L1) > 0:
            if  x not in L1:
                print
            else:
                L2.append(x)
                L1.remove(x)
                _tmp=choice(L1)
                print("the random value is:"+_tmp)

                with open(savefile,'a+') as f:
                    f.write('['+x+']' +"===VS==="+'['+_tmp+']'+'\n')
                    f.close()
                print('['+x+']' +"===VS==="+'['+_tmp+']')
                L2.append(_tmp)
                L1.remove(_tmp)
    #            print("the len of list is:"+str(len(L1)))
                print(L1)

    ## show the result of the List
    print(L2)

    ban40()
    print("对阵结果为：")
    ban40()
    f = open(savefile, "r")
    lines = f.readlines()
    for line in lines:
        print(line)
    ban40()

